package com.ruoyi.web.controller.app;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.app.domain.vo.AppSalesOrderVo;
import com.ruoyi.app.domain.bo.AppSalesOrderBo;
import com.ruoyi.app.service.IAppSalesOrderService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 充值订单
 *
 * @author heise
 * @date 2025-06-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/salesOrder")
public class AppSalesOrderController extends BaseController {

    private final IAppSalesOrderService iAppSalesOrderService;

    /**
     * 查询充值订单列表
     */
    @SaCheckPermission("system:salesOrder:list")
    @GetMapping("/list")
    public TableDataInfo<AppSalesOrderVo> list(AppSalesOrderBo bo, PageQuery pageQuery) {
        return iAppSalesOrderService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出充值订单列表
     */
    @SaCheckPermission("system:salesOrder:export")
    @Log(title = "充值订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AppSalesOrderBo bo, HttpServletResponse response) {
        List<AppSalesOrderVo> list = iAppSalesOrderService.queryList(bo);
        ExcelUtil.exportExcel(list, "充值订单", AppSalesOrderVo.class, response);
    }

    /**
     * 获取充值订单详细信息
     *
     * @param salesOrderId 主键
     */
    @SaCheckPermission("system:salesOrder:query")
    @GetMapping("/{salesOrderId}")
    public R<AppSalesOrderVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long salesOrderId) {
        return R.ok(iAppSalesOrderService.queryById(salesOrderId));
    }

    /**
     * 新增充值订单
     */
    @SaCheckPermission("system:salesOrder:add")
    @Log(title = "充值订单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AppSalesOrderBo bo) {
        return toAjax(iAppSalesOrderService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改充值订单
     */
    @SaCheckPermission("system:salesOrder:edit")
    @Log(title = "充值订单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AppSalesOrderBo bo) {
        return toAjax(iAppSalesOrderService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除充值订单
     *
     * @param salesOrderIds 主键串
     */
    @SaCheckPermission("system:salesOrder:remove")
    @Log(title = "充值订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{salesOrderIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] salesOrderIds) {
        return toAjax(iAppSalesOrderService.deleteWithValidByIds(Arrays.asList(salesOrderIds), true) ? 1 : 0);
    }
}
